package com.szhn.aclservice.controller;


import com.szhn.aclservice.entity.AclPermission;
import com.szhn.aclservice.entity.vo.AclPermissionVo;
import com.szhn.aclservice.service.AclPermissionService;
import com.szhn.common.responsejson.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-10-28
 */
@RestController
@RequestMapping("/aclservice/acl-permission")
@CrossOrigin
public class AclPermissionController {

    @Autowired
    private AclPermissionService aclPermissionService;


    @ApiOperation("递归获取全部菜单")
    @GetMapping("getAll")
    public R getAll(){
        List<AclPermissionVo> list = aclPermissionService.getAll();
        return R.ok().data("list",list);
    }


    @ApiOperation("根据id递归删除菜单")
    @DeleteMapping("deleteById/{id}")
    public R deleteById(@PathVariable String id){
        aclPermissionService.deleteById(id);
        return R.ok();
    }

    @ApiOperation("新增菜单")
    @PostMapping("addMenu")
    public R addMenu(@RequestBody AclPermission aclPermission){
        boolean save = aclPermissionService.save(aclPermission);
        return R.ok();
    }

    @ApiOperation("修改菜单")
    @PutMapping("update")
    public R update(@RequestBody AclPermission aclPermission){
        boolean b = aclPermissionService.updateById(aclPermission);
        return R.ok();
    }

    @ApiOperation("给角色分配权限")
    @PostMapping("doAssin")
    public R doAssin(String roleId,String[] permissionId){
        aclPermissionService.saveRoleAndPermission(roleId,permissionId);
        return R.ok();
    }

}

